/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wii.elpro.web.filter;

import com.wii.elpro.dao.HibernateUtil;
import java.io.*;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author hendro
 */
public class HibernateServletFilter implements Filter {
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)
    throws IOException,ServletException{
        try{            
            chain.doFilter(request,response);
            HibernateUtil.commitTransaction();
            System.out.println("Session Commit...");
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            try {
                HibernateUtil.closeSession();
                System.out.println("Session diclose...");
            } catch (Exception ex) {
                Logger.getLogger(ServletFilter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    public void init(FilterConfig filterConfig) throws ServletException {
    }
    
    public void destroy() {
    }
}